package View;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.WindowConstants;

import mvc.Controller;
import mvc.Model;
import mvc.View;
import Controller.*;
import Model.*;

public class ViewMenu extends JPanel implements ActionListener, View {
	JButton facil;
	JButton normal;
	JButton complicado;
	JButton imposible;
	
	JLabel lbl;
	JFrame viewFrame, controlFrame;
	Timer timer;
	JPanel viewPanel;
	
	ControllerMenu controller;
	public ViewMenu(ControllerMenu controller)
	{
		this.controller = controller;
	}
	public void createView() {
		// Create all Swing components here
        //viewPanel = new JPanel(new GridLayout(1, 2));
        viewFrame = new JFrame("View");
        viewFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        viewFrame.setSize(new Dimension(800,600));
      
        viewFrame.add(this);
        
        setFocusable(true);
        setBackground(Color.BLACK);
        //setDoubleBuffered(true);
        //viewFrame.setVisible(true);
        //viewFrame.setLayout(new BoxLayout(viewFrame.getContentPane(),BoxLayout.Y_AXIS));
        viewFrame.add(createTitulo(),BorderLayout.NORTH);
        viewFrame.add(createControls(),BorderLayout.CENTER);
		viewFrame.pack();
		viewFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		viewFrame.setVisible(true);
	}
	
	private JPanel createControls(){
	
		JPanel buttonPanel = new JPanel();
		//viewFrame.setLayout(new BoxLayout(viewFrame.getContentPane(),BoxLayout.Y_AXIS));
		facil = new JButton("Facil");
		normal = new JButton("Normal");
		complicado = new JButton("Complicado");
		imposible = new JButton("Imposible");
		buttonPanel.add(facil);
		buttonPanel.add(normal);
		buttonPanel.add(complicado);
		buttonPanel.add(imposible);
		facil.addActionListener(this);
		normal.addActionListener(this);
		complicado.addActionListener(this);
		imposible.addActionListener(this);
		
		return buttonPanel;
		
	}
	private JPanel createTitulo(){
		JPanel tituloPanel = new JPanel();
		JLabel titulo =new JLabel("Rtype");
		titulo.setFont(new java.awt.Font("Tahoma", 0, 36)); 
		tituloPanel.add(titulo,BorderLayout.NORTH);
		tituloPanel.add(new JLabel("Elija dificultad"),BorderLayout.SOUTH);
		return tituloPanel;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		viewFrame.setVisible(false);
		if(e.getSource() == facil)
			controller.facil();
		else if(e.getSource()==normal)
			controller.normal();
		else if(e.getSource()==complicado)
			controller.complicado();
		else if(e.getSource()==imposible)
			controller.imposible();
		
		
	}
	@Override
	public Controller getController() {
		
		return controller;
	}
	@Override
	public void setController(Controller c) {
		controller = (ControllerMenu) c;
		
	}
	@Override
	public Model getModel() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void setModel(Model m) {
		// TODO Auto-generated method stub
		
	}
}
